package com.styytech.dadabao.utils;

import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class DateUtil {
	private static final String FORMAT = "yyyy-MM-dd HH:mm:ss";

	public static String date2Str(Calendar paramCalendar) {
		return date2Str(paramCalendar, null);
	}

	public static String date2Str(Calendar paramCalendar, String paramString) {
		if (paramCalendar == null)
			return null;
		return date2Str(paramCalendar.getTime(), paramString);
	}

	public static String date2Str(Date paramDate) {
		return date2Str(paramDate, null);
	}

	public static String date2Str(Date paramDate, String paramString) {
		if (paramDate == null)
			return null;
		if ((paramString == null) || (paramString.length() == 0))
			paramString = "yyyy-MM-dd HH:mm:ss";
		return new SimpleDateFormat(paramString).format(paramDate);
	}

//	public static String format(long paramLong)
//	  {
//	    int i = 1000 * 60;
//	    int j = i * 60;
//	    int k = j * 24;
//	    long l1 = paramLong / k;
//	    long l2 = (paramLong - l1 * k) / j;
//	    long l3 = (paramLong - l1 * k - l2 * j) / i;
//	    long l4 = (paramLong - l1 * k - l2 * j - l3 * i) / 1000;
//	    long l5 = paramLong - l1 * k - l2 * j - l3 * i - l4 * 1000;
//	    String str1;
//	    String str2;
//	    label176: String str3;
//	    label207: String str4;
//	    label238: String str5;
//	    if (l1 < 10L)
//	    {
//	      str1 = "0" + l1;
//	      if (l2 >= 10L)
//	        break label381;
//	      str2 = "0" + l2;
//	      if (l3 >= 10L)
//	        break label406;
//	      str3 = "0" + l3;
//	      if (l4 >= 10L)
//	        break label431;
//	      str4 = "0" + l4;
//	      if (l5 >= 10L)
//	        break label456;
//	      str5 = "0" + l5;
//	      label269: if (l5 >= 100L)
//	        break label481;
//	    }
//	    label406: label431: label456: label481: for (String str6 = "0" + str5; ; str6 = "" + str5)
//	    {
//	      return str1 + " " + str2 + ":" + str3 + ":" + str4 + " " + str6;
//	      str1 = "" + l1;
//	      break;
//	      label381: str2 = "" + l2;
//	      break label176;
//	      str3 = "" + l3;
//	      break label207;
//	      str4 = "" + l4;
//	      break label238;
//	      str5 = "" + l5;
//	      break label269;
//	    }
//	  }

	public static String getCurDateStr() {
		Calendar localCalendar = Calendar.getInstance();
		localCalendar.setTime(new Date());
		return localCalendar.get(1) + "-" + (1 + localCalendar.get(2)) + "-"
				+ localCalendar.get(5) + "-" + localCalendar.get(11) + ":"
				+ localCalendar.get(12) + ":" + localCalendar.get(13);
	}

	public static String getCurDateStr(int paramInt) {
		Calendar localCalendar = Calendar.getInstance();
		localCalendar.add(13, paramInt);
		localCalendar.setTime(localCalendar.getTime());
		return localCalendar.get(1) + "-" + (1 + localCalendar.get(2)) + "-"
				+ localCalendar.get(5) + "-" + localCalendar.get(11) + ":"
				+ localCalendar.get(12) + ":" + localCalendar.get(13);
	}

	public static String getCurDateStr(String paramString) {
		return date2Str(Calendar.getInstance(), paramString);
	}

	public static String getDays(long paramLong) {
		long l = paramLong / (24 * (60 * (1 * 60)));
		if (l < 1L)
			return "1";
		return String.valueOf(l);
	}

	public static float getFormatNumber(float paramFloat) {
		return Float.parseFloat(new DecimalFormat("#0.00").format(paramFloat));
	}

	public static String getMillon(long paramLong) {
		return new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss").format(Long
				.valueOf(paramLong));
	}

	public static String getSMillon(long paramLong) {
		return new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss-SSS").format(Long
				.valueOf(paramLong));
	}

	public static String getSpecialTime(long paramLong) {
		return new SimpleDateFormat("MM月dd日  HH:mm").format(Long
				.valueOf(paramLong));
	}

	public static boolean isNumeric(String paramString) {
		return Pattern.compile("[0-9]*").matcher(paramString).matches();
	}

	public static Calendar str2Calendar(String paramString) {
		return str2Calendar(paramString, null);
	}

	public static Calendar str2Calendar(String paramString1, String paramString2) {
		Date localDate = str2Date(paramString1, paramString2);
		if (localDate == null)
			return null;
		Calendar localCalendar = Calendar.getInstance();
		localCalendar.setTime(localDate);
		return localCalendar;
	}

	public static Date str2Date(String paramString) {
		return str2Date(paramString, null);
	}

	public static Date str2Date(String paramString1, String paramString2) {
		if ((paramString1 == null) || (paramString1.length() == 0))
			return null;
		if ((paramString2 == null) || (paramString2.length() == 0))
			paramString2 = "yyyy-MM-dd HH:mm:ss";
		try {
			Date localDate = new SimpleDateFormat(paramString2)
					.parse(paramString1);
			return localDate;
		} catch (Exception localException) {
			localException.printStackTrace();
		}
		return null;
	}
}